import baseUrl from "./baseUrl"
import qs from "./qs"

var request = function(config) {
	return new Promise((resolve, rejected) => {
		var setting = {
			url: baseUrl + config.url,
			method: config.method ? (config.method).toUpperCase() : "GET",
			// method: (config.method).toUpperCase() || "GET",
			data: config.data,
			header: {
				// "content-type":"application/x-www-form-urlencoded",
				"token":uni.getStorageSync('token'),
			},
			timeout: 5000,
			success(res) {
				resolve(res.data)
				
			},
			fail(res) {
				rejected(res)
			}
		}
		
		// if (config.method) {
		// 	if (config.method.toUpperCase() == "POST") {
		// 		setting.header["content-type"] = "application/json";
		// 		setting.data = qs.stringify(setting.data, {
		// 			allowDots: true
		// 		})
		// 	} else {
		// 		setting.header["content-type"] = "application/x-www-form-urlencoded"
		// 	}
		// } else {
		// 	setting.header["content-type"] = "application/json"
		// }
		
		uni.request(setting)
	})

};
export default request
